package com.xjrsoft.module.visual.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjrsoft.common.core.VoToColumn;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.visual.dto.GetListKbInfoDto;
import com.xjrsoft.module.visual.dto.KbInfoDto;
import com.xjrsoft.module.visual.entity.XjrKbInfo;
import com.xjrsoft.module.visual.mapper.XjrKbInfoMapper;
import com.xjrsoft.module.visual.service.IXjrKbInfoService;
import com.xjrsoft.module.visual.vo.KbInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 看板基础信息表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-11-18
 */
@Service
public class XjrKbInfoServiceImpl extends ServiceImpl<XjrKbInfoMapper, XjrKbInfo> implements IXjrKbInfoService {

    /**
    * @Author:湘北智造-框架开发组
    * @Date:2020/11/19
    * @Param:[dto]
    * @return:com.xjrsoft.common.page.PageOutput<com.xjrsoft.module.visual.vo.XjrKbInfoVo>
    * @Description:查询分页
    */
    @Override
    public PageOutput<KbInfoVo> getPageList(GetListKbInfoDto dto) {
        QueryWrapper<XjrKbInfo> query = new QueryWrapper<>();
        query.select(XjrKbInfo.class, x -> VoToColumn.Convert(KbInfoVo.class).contains(x.getColumn()));
        query.lambda().like(StringUtils.isNotBlank(dto.getKeyword()), XjrKbInfo::getKanBanName, dto.getKeyword());
        IPage<XjrKbInfo> xjrKbInfoIPage = baseMapper.selectPage(ConventPage.getPage(dto), query);
        return ConventPage.getPageOutput(xjrKbInfoIPage, KbInfoVo.class);
    }

    @Override
    public boolean saveKbInfo(KbInfoDto kbInfoDto) {
        XjrKbInfo xjrKbInfo = BeanUtil.copy(kbInfoDto, XjrKbInfo.class);
        return baseMapper.insert(xjrKbInfo) > 0;
    }

    @Override
    public boolean updateKbInfo(String id, KbInfoDto kbInfoDto) {
        XjrKbInfo xjrKbInfo = BeanUtil.copy(kbInfoDto, XjrKbInfo.class);
        xjrKbInfo.setId(id);
        return baseMapper.updateById(xjrKbInfo) > 0;
    }
}
